import { MockMethod } from "vite-plugin-mock";

const users :any= {
	'admin-token': {
		roles: ['admin'],
		name: 'Admin'
	},
	'guest-token': {
		roles: ['guest'],
		name: 'Guest'
	}
}

// 添加不同按钮权限到/permission/button页面中
function setDifAuthority(authority: any, routes: any) {
  routes.children[1].meta.authority = [authority];
  return routes;
}

export default [
  {
		url: '/api/user/login',
		method: 'post',
		response: (config: any) => {
			const { username, password } = config.body
			if (password !== '123456') {
				return {
					code: 500,
					message: '用户名密码错误'
				}
			}
			const token = 'admin-token'
			if (!token) {
				return {
					code: 500,
					message: '用户名密码错误'
				}
			}
			return {
				code: 200,
				message: 'ok',
				data: token
			}
		}
	},
  {
		url: '/api/user/info',
		method: 'get',
		response: (config: any) => {
			const { token } = config.query
			const info = users[token]
			if (!info) {
				return {
					code: 500,
					message: '找不到该用户'
				}
			}
			return {
				code: 200,
				data: info,
				message: 'ok'
			}
		}
	},
] as MockMethod[];
